<div id="page-content">
	<div class="col-sm-12 eq-box-sm">
		<div class="panel">
			<div class="panel panel-search">
				<div class="panel-body">
					<div class="form-inline">
						<div class="form-group">
							<input id="applyUser" placeholder="申请人" class="form-control">
						</div>
						<div class="form-group">
							<div class="input-group date form_datetime">
								<input id="searchStartTime" placeholder="开始时间" class="form-control">
								<span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
							</div>
						</div>
						<div class="form-group">
							<div class="input-group date form_datetime">
								<input id="searchEndTime" placeholder="结束时间" class="form-control">
								<span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
							</div>
						</div>
						<div class="form-group">
							<button class="btn btn-primary" type="button" onclick="searchTable()">搜索</button>
						</div>
					</div>
				</div>
			</div>
			<div class="panel ">
				<div class="panel-body">
					<a id="add" class="btn btn-primary data-toolbar" href="#(ctx)/admin/oa/apply/common/getEditPage?view=edit"><i class="demo-pli-add"></i> 添加</a>
					<a id="del" class="btn btn-danger data-toolbar" onclick="delSel()" href="javascript:void(0);"><i class="demo-pli-cross"></i> 批量删除</a>
					<table id="pageTable" class="demo-add-niftycheck" data-toolbar="#del,#add"
						   data-search="true"
						   data-show-refresh="true"
						   data-show-toggle="true"
						   data-show-columns="true"
						   data-sort-name="id"
						   data-page-list="[5, 10, 20]"
						   data-page-size="5"
						   data-pagination="true" data-show-pagination-switch="true" ></table>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	var type = "#(type)";
	var col = [{field: 'checked', checkbox : true, align: 'center'},
		{field: 'applyer_name', title: '申请人', align: 'center'},
		{field: 'org_name', title: '部门名称', align: 'center'},
		{field: 'type_name', title: '申请类型', align: 'center'},
		{field: 'reason', title: '申请原因', align: 'center'},
		{field: 'create_time', title: '创建时间', align: 'center'},
		{field: 'note', title: '备注1', align: 'center'},
		{field: 'note2', title: '备注2', align: 'center'},
		{field: 'if_submit', title: '是否提交', align: 'center', width:'80',
			formatter:function(value,row,index){
				if(value=="1"){
					return "<span style='color:green'>已提交</span>";
				}else{
					return "未提交";
				}
			}
		},
		{field: 'if_complete', title: '是否完成', align: 'center', width:'80',
			formatter:function(value,row,index){
				if(value=="1"){
					return "<span style='color:green'>已完成</span>";
				}else{
					return "<span style='color:red'>未完成</span>";
				}
			}
		},
		{field: 'if_agree', title: '是否同意', align: 'center', width:'80',
			formatter:function(value,row,index){
				if(value=="1"){
					return "<span style='color:green;'>同意</span>";
				}else if(value=="2"){
					return "<span style='color:red;'>未同意</span>";
				}else{
					return "<span style='color:gray;'>未知</span>";
				}
			}
		},
		{field: 'if_submit', title: '操作', align: 'left', width:'200',
			formatter:function(value,row,index){
				//通过formatter可以自定义列显示的内??
				//value：当前field的???，即id
				//row：当前行的数??
				var a = '';
				if(value=='0'){//未提交
					a = a + '<a class="label label-table label-info" onclick="startProcess(\''+row.id+'\')" href="javascript:void(0);" >提交</a>&nbsp;';
					a = a + '<a class="label label-table label-success" href="'+ctx+'/admin/oa/apply/common/getEditPage?id='+row.id+'&view=detail&type="+type >查看</a>&nbsp;';
					a = a + '<a class="label label-table label-success" href="'+ctx+'/admin/oa/apply/common/getEditPage?id='+row.id+'&view=edit&type="+type >编辑</a>&nbsp;';
					a = a + '<a class="label label-table label-danger" onclick="del(\''+row.id+'\')" href="javascript:void(0);" >删除</a>';
				}else{
					a = a + '<a class="label label-table label-info" href="javascript:void(0);" onclick="pointLion.openTaskHisListPage(\''+row.proc_ins_id+'\')">流转</a>&nbsp;';
					a = a + '<a class="label label-table label-success" href="'+ctx+'/admin/oa/apply/common/getEditPage?id='+row.id+'&view=detail" >查看</a>&nbsp;';
					if(row.if_complete=="0"){
						a = a + '<a class="label label-table label-danger" href="javascript:void(0);" onclick="callBack(\''+row.id+'\')" >撤回</a>&nbsp;';

					}
				}
				return a;
			}
		}];
	var opt = {
		//请求方法
		method: 'get',
		//是否显示行间隔色
		striped: true,
		//是否使用缓存，默认为true，所以一般情况下??要设置一下这个属性（*??
		cache: false,
		//data-toolbar: "#demo-delete-row",
		//是否显示分页
		pagination: true,
		//是否启用排序
		sortable: false,
		//排序方式
		sortOrder: "asc",
		//初始化加载第页，默认第一
		//我设置了这一项，但是貌似没起作用，???且我这默认??0,- -
		//pageNumber:1,
		//每页的记录行数
		pageSize: 10,
		//可供选择的每页的行数
		pageList: [10, 25, 50, 100],
		//这个接口??要处理bootstrap table传???的固定参数,并返回特定格式的json数据
		url: ctx+"/admin/oa/apply/common/listData",
		//默认值为 'limit',传给服务端的参数为：limit, offset, search, sort, order Else
		//queryParamsType:'',
		////查询参数,每次调用是会带上这个参数，可自定??
		queryParams : function(params) {
			return {
				pageNumber: (params.offset/params.limit)+1,
				pageSize: params.limit,
				type: type
			};
		},
		//分页方式：client客户端分页，server服务端分页（*??
		sidePagination: "server",
		//是否显示搜索
		search: false,
		//Enable the strict search.
		strictSearch: true,
		//Indicate which field is an identity field.
		idField : "id",
		columns: col,
		pagination:true,paginationShowPageGo: true
	};

	//表格
	function initTable(){
		$('#pageTable').bootstrapTable(opt);
		$('#pageTable').bootstrapTable('hideColumn', 'id');
	}
	function refreshTable(){
		$("#pageTable").bootstrapTable('refresh', opt);
		$('#pageTable').bootstrapTable('hideColumn', 'id');
	}

	//批量删除
	function delSel(){
		var data = [];
		$("#pageTable input[type='checkbox'][name!='btSelectAll']:checked").each(function(){
			data.push($(this).val());
		});
		if(data.length==0){
			pointLion.alertMsg("请???择要删除的数据!","danger",null,null);
			return;
		}
		del(data.join(","));//执行删除
	}
	//删除
	function del(ids){
		pointLion.confimMsg("您是否要删除所选信息 ?<br/> 点击确认进行删除 , 点击取消取消该操作",null,function(){
			//执行删除
			var data = common_ajax.ajaxFunc("/admin/oa/apply/common/delete",{"ids":ids}, "json", null);
			//删除结果
			if(data.success){
				pointLion.alertMsg(data.message,"success",null,function(){
					location.href = ctx+'/admin/oa/apply/common/getListPage';//跳转到列表页
				});
			}else{
				pointLion.alertMsg(data.message,"success",null,null);
			}
		});
	};
	//提交，启动流程
	function startProcess(id){
		pointLion.confimMsg("您将要提交该单据！并且启动流??<br/><span style='color:green;'>您将无法进行修改和删除！！！</span> <br/>点击确认进行提交 , 点击取消取消该操??",null,function(){
			var data = common_ajax.ajaxFunc("/admin/oa/apply/common/startProcess",{"id":id}, "json", null);
			if(data.success){
				pointLion.alertMsg(data.message,"success",null,function(){
					location.href = ctx+'/admin/oa/apply/common/getListPage';//跳转到列表页
				});
			}else{
				pointLion.alertMsg(data.message,"danger",null,null);
			}
		});
	}
	//撤回
	function callBack(id){
		pointLion.confimMsg("您将要撤回该单据流程??<br/><span style='color:red;'>该操作将取回单据，您将可以对单据进行修改，并可将单据重新送交审批??</span> <br/>点击确认进行撤回单据 , 点击取消取消该操??",null,function(){
			//执行删除
			var data = common_ajax.ajaxFunc("/admin/oa/apply/common/callBack",{"id":id}, "json", null);
			//删除结果
			if(data.success){
				pointLion.alertMsg(data.message,"success",null,function(){
					location.href = ctx+'/admin/oa/apply/common/getListPage';//跳转到列表页
				});
			}else{
				pointLion.alertMsg(data.message,"danger",null,null);
			}
		});
	}
	//查询
	function searchTable(){
		var startTime = $("#searchStartTime").val();
		var endTime = $("#searchEndTime").val();
		var applyUser = $("#applyUser").val();
		var param = {
			query: {
				"startTime":startTime,
				"endTime":endTime,
				"applyUser":applyUser,
				"type":type
			}
		}
		// 刷新表格
		$('#pageTable').bootstrapTable('refresh',param);
	}
	$(document).ready(function(){
		$('.form_datetime').datepicker({format: 'yyyy-mm-dd',weekStart: 1,todayBtn:  1,autoclose: 1,language:  'zh-CN',todayHighlight: 1,forceParse: 0,clearBtn: true }).on('changeDate',null);
		initTable();//初始数据
	});
</script>